package com.share.device.controller;

import com.share.common.core.web.controller.BaseController;
import com.share.common.core.web.domain.AjaxResult;
import com.share.common.core.web.page.TableDataInfo;
import com.share.device.domain.Cabinet;
import com.share.device.service.ICabinetService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 充电宝柜机表 前端控制器
 * </p>
 *
 * @author pww
 * @since 2025-03-24
 */
@RestController
@Tag(name = "CabinetController", description = "充电宝柜机表")
@RequestMapping("/cabinet")
public class CabinetController extends BaseController {
    @Autowired
    private ICabinetService cabinetService;


    /**
     * 获取充电宝柜机全部详细信息
     * @param id
     * @return
     */
    @Operation(summary = "获取充电宝柜机全部详细信息")
    @GetMapping(value = "/getAllInfo/{id}")
    public AjaxResult getAllInfo(@PathVariable Long id) {
        return success(cabinetService.getAllInfo(id));
    }


    /**
     * 查询未使用充电宝列表
     *
     * @param keyWord
     * @return
     */
    @Operation(summary = "查询未使用充电宝列表")
    @GetMapping("/searchNoUseList/{keyWord}")
    public AjaxResult searchNoUseList(@PathVariable String keyWord) {
        return success(cabinetService.searchNoUseList(keyWord));
    }


    /**
     * 删除充电宝柜机
     *
     * @param ids
     * @return
     */
    @Operation(summary = "删除充电宝柜机")
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<Long> ids) {
        AjaxResult ajaxResult = toAjax(cabinetService.removeCabinet(ids));
        return ajaxResult;
    }

    /**
     * 修改充电宝柜机
     *
     * @param cabinet
     * @return
     */
    @PutMapping
    @Operation(summary = "修改充电宝柜机")
    public AjaxResult update(@RequestBody Cabinet cabinet) {
        return toAjax(cabinetService.updateCabinet(cabinet));
    }


    /**
     * 新增充电宝柜机
     *
     * @param cabinet
     * @return
     */
    @Operation(summary = "新增充电宝柜机")
    @PostMapping
    public AjaxResult add(@RequestBody Cabinet cabinet) {
        boolean is_success = cabinetService.saveCabinet(cabinet);
        AjaxResult result = toAjax(is_success);
        return result;
    }

    /**
     * 获取充电宝详细信息
     *
     * @param id 充电宝id
     * @return
     */
    @Operation(summary = "获取充电宝柜机详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable Long id) {
        return success(cabinetService.getById(id));
    }

    @Operation(summary = "查询充电宝柜机列表")
    @GetMapping("/list")
    public TableDataInfo list(Cabinet cabinet) {
        // 开始分页
        startPage();
        List<Cabinet> list = cabinetService.selectListCabinet(cabinet);
        // 获取分页信息
        TableDataInfo tDataInfo = getDataTable(list);
        return tDataInfo;
    }

}
